package com.tsingtree.modular.controller.view;

import com.tsingtree.base.auth.annotion.Permission;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.tsingtree.modular.entity.NanSeller;
import com.tsingtree.modular.entity.NanSellerProducts;
import com.tsingtree.modular.model.params.NanSellerProductsParam;
import com.tsingtree.modular.service.NanSellerProductsService;
import com.tsingtree.modular.service.NanSellerService;
import com.tsingtree.roses.core.base.controller.BaseController;
import com.tsingtree.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 运营组-商品控制器
 *
 * @author jagger
 */
@Controller
@RequestMapping("/nanSellerProducts")
public class NanSellerProductsController extends BaseController {

    private String PREFIX = "/nanSellerProducts";

    @Autowired
    private NanSellerProductsService nanSellerProductsService;

    /**
     * 跳转到主页面
     *
     * @author jagger
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/nanSellerProducts.html";
    }

    /**
     * 新增页面
     *
     * @author jagger
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/nanSellerProducts_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jagger
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/nanSellerProducts_edit.html";
    }

    /**
     * 商品选择器页面
     *
     * @author jagger
     */
    @RequestMapping("/choose")
    public String choose() {
        return PREFIX + "/nanSellerProductsChoose.html";
    }

    /**
     * 新增接口
     *
     * @author jagger
     */
    @RequestMapping("/addItem")
    @Permission
    @ResponseBody
    public ResponseData addItem(NanSellerProductsParam nanSellerProductsParam) {
        this.nanSellerProductsService.add(nanSellerProductsParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jagger
     */
    @RequestMapping("/editItem")
    @Permission
    @ResponseBody
    public ResponseData editItem(NanSellerProductsParam nanSellerProductsParam) {
        this.nanSellerProductsService.update(nanSellerProductsParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jagger
     */
    @RequestMapping("/delete")
    @Permission
    @ResponseBody
    public ResponseData delete(NanSellerProductsParam nanSellerProductsParam) {
        nanSellerProductsParam.setIsDel(true);
        this.nanSellerProductsService.update(nanSellerProductsParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jagger
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(NanSellerProductsParam nanSellerProductsParam) {
        NanSellerProducts detail = this.nanSellerProductsService.getById(nanSellerProductsParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jagger
     */
    @ResponseBody
    @Permission
    @RequestMapping("/list")
    public LayuiPageInfo list(NanSellerProductsParam nanSellerProductsParam) {
        return this.nanSellerProductsService.findPageBySpec(nanSellerProductsParam);
    }

    /**
     * 商品选择器专用列表接口（无权限验证）
     * 仅返回已上线且未删除的商品
     *
     * @author jagger
     */
    @ResponseBody
    @RequestMapping("/listForChoose")
    public LayuiPageInfo listForChoose(NanSellerProductsParam nanSellerProductsParam) {
        // 强制设置查询条件：只查询已上线且未删除的商品
        nanSellerProductsParam.setIsDel(false);  // Boolean 类型
        nanSellerProductsParam.setIsOnline(1);   // Integer 类型，1表示已上线
        return this.nanSellerProductsService.findPageBySpec(nanSellerProductsParam);
    }

}


